#!/bin/bash

timestamp=`date "+%Y-%m-%d %H:%M:%S"`

# MySQL连接参数
MYSQL_HOST="127.0.0.1"
MYSQL_PORT="3306"
MYSQL_USER="root"
MYSQL_PASSWORD="xxxxx@fit2024"

mysqladmin ping -h $MYSQL_HOST -P $MYSQL_PORT -u $MYSQL_USER -p$MYSQL_PASSWORD &>/dev/null

# 检查命令的退出状态
if [ $? -eq 0 ]; then
    exit 0  # 返回 0 表示脚本执行成功
else
    echo "$timestamp: MySQL is not healthy."
    exit 1  # 返回非零值表示脚本执行失败
fi
